Setting up EventBridge Scheduler for Billing
This guide explains how to set up AWS EventBridge Scheduler to trigger the Atom SaaS billing engine periodically. This is the "Serverless Cron" pattern suitable for ATOM Cloud deployments.
Prerequisites
- **Deploy the latest backend code** (must include
/api/billing/admin/report-usage). - **Generate an
ADMIN_API_KEY**:
- This is a shared secret between your AWS EventBridge and your Atom Backend.
- Generate one:
openssl rand -hex 32 - Add it to your Vault secrets:
atom-cli secrets set ADMIN_API_KEY=your_generated_key
Setup Steps (AWS Console)
- **Go to Amazon EventBridge** -> **Scheduler** -> **Schedules**.
- Click **Create schedule**.
- **Schedule detail**:
- **Name**:
atom-billing-hourly - **Schedule pattern**: **Recurring schedule**
- **Cron-based schedule**:
0 * * * ? *(Runs at minute 0 of every hour) - **Flexible time window**: **Off** (or 5 minutes if you don't mind variance)
- **Target detail**:
- **Target API**: **Universal Target**
- **Select target**: **HTTPS** (Send data to an HTTPS endpoint)
- **URL**:
https://[tenant].atomagentos.com/api/billing/admin/report-usage(Replace with your actual domain) - **Method**:
POST - **HTTP Headers**:
- **Name**:
x-api-key - **Value**:
your_generated_key(TheADMIN_API_KEYyou set in ATOM Cloud)
- **Settings**:
- **Retry policy**: Retry 3 times.
- **Permissions**: Create a new execution role (AWS will handle this automatically).
Verification
- Wait for the top of the hour, or manually trigger the schedule.
- Check your application logs (
atom-cli logs). You should see: - Check Stripe Dashboard -> Subscriptions -> Usage to confirm the increment.